// components/product/product-item/index.js
import componentBehavior from '../../../behaviors/component';
import { COMPONENT_OPTIONS } from '../../../constants/common';
import { getMaxNumber } from '../../../common/utils';

Component({
    behaviors: [componentBehavior],
    options: {
        ...COMPONENT_OPTIONS,
    },
    properties: {
        productInfo: {
            type: Object,
            value: {},
        },
        noneHasStepper: {
            type: Boolean,
            value: true,
        },
    },
    observers: {
        'productInfo': function (val) {
            if (val) {
                const maxCount = val.selectSku && val.selectSku.maximum != -1 ? (val.selectSku.maximum - val.selectSku.freezeQuantity) : getMaxNumber();
                this.setData({ maxCount });
            }
        },
    },
    data: {
        maxCount: getMaxNumber(),
    },
    methods: {
        handleChange(e) {
            const { productInfo } = this.data;
            productInfo.count = e.detail;
            this.triggerEvent('change', productInfo);
        },
    }
})

